import type { RemoveMethods } from "@/types/remove-methods";
import { LifeModelData } from "@model/lifeModel";

export class TimeManage {
  id: number;
  startTime: number;
  endTime: number;
  desc: string;
  fatherId: number;

  setInfo(data: RemoveMethods<TimeManage>) {
    Object.assign(this, data);
  }

  constructor(id: number, startTime: number, endTime: number, desc: string, fatherId: number) {
    this.id = id;
    this.startTime = startTime;
    this.endTime = endTime;
    this.desc = desc;
    this.fatherId = fatherId;
  }
}

export class TimeManageList {
  timeManageList: Array<TimeManage>;

  setInfo(data: TimeManageList) {
    // Object.assign(this, data);
    this.timeManageList = data.timeManageList;
  }

  constructor(timeManageList: Array<TimeManage>) {
    this.timeManageList = timeManageList;
  }
  getTimeManageById(id: number | undefined) {
    return this.timeManageList.find(value => value.id === id);
  }
  deleteTimeManageById(id: number) {
    this.timeManageList = this.timeManageList.filter(item => item.id !== id);
  }
  addTimeManage(timeManage: TimeManage) {
    this.timeManageList.push(timeManage);
  }
  getTimeManageSelectOptions(lifeModelData: LifeModelData | undefined) {
    const result = [];
    if (lifeModelData !== undefined) {
      const timeManageList = lifeModelData.timeManageList;
      const list = new Set<number>();
      for (let i = 0; i < timeManageList.length; i++) {
        list.add(timeManageList[i]);
      }
      for (let i = 0; i < this.timeManageList.length; i++) {
        const data = this.timeManageList[i];
        if (list.has(data.id)) {
          result.push({
            label: data.desc,
            value: data.id,
          });
        }
      }
    }
    return result;
  }
  getTimeManageSelectOptions2(timeManageList: Array<number>): Array<{ label: string; value: number }> {
    const result = [];
    if (timeManageList !== undefined && timeManageList.length > 0) {
      const list = new Set<number>();
      for (let i = 0; i < timeManageList.length; i++) {
        list.add(timeManageList[i]);
      }
      for (let i = 0; i < this.timeManageList.length; i++) {
        const data = this.timeManageList[i];
        if (list.has(data.id)) {
          result.push({
            label: data.desc,
            value: data.id,
          });
        }
      }
    }
    return result;
  }
}
